package com.xigua._搜索或回溯算法;

import com.xigua.TreeNode;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/3/2020:24
 */
public class _剑指Offer55_2_平衡二叉树 {


    public boolean isBalanced(TreeNode root) {
        return root == null ?true: Math.abs(maxDepth(root.left)-maxDepth(root.right))<=1 && isBalanced(root.left) && isBalanced(root.right);
    }

    int maxDepth(TreeNode root){
        return  root == null ? 0 : Math.max(maxDepth(root.left),maxDepth(root.right))+1;
    }





}
